<template>
	<view>
	<!-- 	选择收货地址 -->
	<view class="address-choose-box" v-if="JSON.stringify(address) === '{}'">
		<button type="primary" size="mini" class="address-btn" @click="chooseAddress">您还未选择收货地址 +</button>
	</view>
	<!-- 收货地址信息 -->
	<view class="address-info-box" v-else @click="chooseAddress">
		<view class="row1">
			<view class="left-box">
				<view class="username"> 收获人: <text>{{address.userName}}</text></view>
			</view>
			<view class="right-box">
				<view class="phone"> 电话: <text>{{address.telNumber}}</text></view>
				<uni-icons type="arrowright" size="16"></uni-icons>
			</view>
		</view>
		<view class="row2">
			<view class="row2-left">收获地址: </view>
			<view class="row2-right">{{addstr}}</view>
		</view>
	</view>
		<!-- 底部的边框线 -->
		<image src="../../static/cart_border@2x.png" class="address-border"></image>
	</view>
</template>

<script>
	import {mapState,mapMutations,mapGetters} from 'vuex'
	export default {
		
		name:"my-address",
		data() {
			return {
				// 使用vux中的数据address，在computed属性中用辅助函数调用
				// address:{}
			};
		},
		computed: {
			// 加载vuex中的数据对象address
			...mapState('m_user',['address']),
			//收货详细地址的计算属性
		...mapGetters('m_user',['addstr'])
		},
		methods:{
			...mapMutations('m_user',['updateAddress']),
		async chooseAddress(){
			const [err,success]	= await uni.chooseAddress().catch(err => err)
			if(err === null && success.errMsg === 'chooseAddress:ok'){
				// 调用vuex中的方法更新地址
				this.updateAddress(success)
				// this.address = success
			
			}
			}
		}
	}
</script>

<style lang="scss">
.address-border{
		display: block;
		width: 100%;
		height: 5px;
}
.address-choose-box{
	display: flex;
	height: 80px;
	justify-content: center;
	align-items: center;
}
.address-info-box{
	 font-size: 12px;
	  height: 90px;
	  display: flex;
	  flex-direction: column;
	  justify-content: center;
	  padding: 0 5px;
	  
	.row1{
		display: flex;
		justify-content: space-between;
		 
		.right-box{
			display: flex;
			align-items: center;
			.phone{
				margin-right: 5px;
			}
		}
	}
	.row2{
		display: flex;
		align-items: center;
		margin-top: 10px;
		.row2-left{
			white-space: nowrap;
		}
		.row2-right{
			padding-left: 5px;
		}
	}
}
</style>
